package operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println();
        System.out.println("*************************");

        Scanner scanner=new Scanner(System.in);

        System.out.println("请输入你要借阅的书名：");
        String input=scanner.nextLine();
        int bnum=bookList.getNum();

        for (int i = 0; i < bnum; i++) {
            Book book=bookList.getBooks(i);

            if (book.isBorrow()){
                System.out.println("不好意思，这本书已经被借出！");
                System.out.println();
                System.out.println("*************************");
                return;
            }

            if (input.equals(book.getName())){
                book.setBorrow(true);
                System.out.println("借阅成功！");
                System.out.println();
                System.out.println("*************************");
                return;
            }

        }
        System.out.println("未找到你要借的书籍！");
        System.out.println();
        System.out.println("*************************");

    }
}
